import { Form } from 'antd';
import { FormInstance } from 'antd/lib/form';
import { NbFormScheme } from './interface';
import useObservableForm from './new/useObservableForm';
import WidgetCell from './widgets/widget.cell';

interface NbFormProps {
  scheme: NbFormScheme;
  form: FormInstance<any>;
}

export default function NbForm(props: NbFormProps) {
  const { scheme, form } = props;
  const { properties, ...formProps } = scheme;
  useObservableForm(scheme.name, form);

  return (
    <Form form={form} {...formProps}>
      <WidgetCell
        widget={'object'}
        properties={properties}
        name={[scheme.name]}
      />
    </Form>
  );
}
